<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'ownMessage.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link rel="stylesheet" href="jquery-easyui-1.4.2/themes/gray/easyui.css">
	<link rel="stylesheet" href="jquery-easyui-1.4.2/themes/icon.css">
	<script src="jquery-easyui-1.4.2/jquery.min.js"></script>
	<script src="jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
	<script src="jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
	<style type="text/css">
	input {
		border-radius:5px;
		border:1px solid #ccc;
		line-height:20px;
	}
</style>
	
	
  </head>
  
  <body>
  	<div id="panel">
		<div style="font-size: 16px; margin: 20px;width: 500px;">
			<div style="font-size: 20px; margin-bottom: 20px;font-weight:bold;">基本信息</div>
			<div ><input id="id" type="hidden" value=<s:property value="#session['user'].id"/> ></div>
			<div id="name" style="width: 200px;margin-top: 10px;">
				<div style="float:left;width:90px;">姓名:</div>
				<font>
					<s:property value="#session['user'].name" />
				</font></div>
			<div id="loginID" style="width: 200px;margin-top: 10px;">
				<div style="float:left;width:90px;">登录名:</div>
				<font>
					<s:property value="#session['user'].loginID" />
				</font>
			</div>
			<div id="gender" style="width: 200px;margin-top: 10px;">
				<div style="float:left;width:90px;">性别:</div>
				<font>
					<s:property value="#session['user'].gender" />
				</font></div>
			<div id="birthday" style="width: 200px;margin-top: 10px;">
				<div style="float:left;width:90px;">出生日期:</div>
				<font>
					<s:property value="#session['user'].birthday" />
					</font></div>
			<div id="phone" style="width: 200px;margin-top: 10px;">
				<div style="float:left;width:90px;">手机号:</div>
				<font>
					<s:property value="#session['user'].cellphone" />
				</font></div>
			<div id="email"style="width: 300px;margin-top: 10px;">
				<div style="float:left;width:90px;">Email:</div>
				<font>
					<s:property value="#session['user'].email" />
				</font></div>
			<div id="searcRoles" style="width: 300px;margin-top: 10px;"></div>
		</div>
	
		<div style="font-size: 16px;margin: 20px;width: 700px; text-align: left;margin-top: 40;">
			<div  style="font-size: 20px; margin-bottom: 20px; margin-top: 10;font-weight:bold;">密码修改</div>
			<div style="padding:5px;">
				<div style="float:left;">原密码:&nbsp;</div>
				<input id="password" type="password" name="password" />
				<font id="passwd" style="color: red;font-size: 15px;margin-left: 10px;"></font>
			</div>
			<div style="padding:5px;">
				<div style="float:left;">新密码:&nbsp;</div>
				<input id="newPassword" type="password" name="newPassword"/>
				<font id="newPasswd" style="color: red;font-size: 15px;margin-left: 10px;"></font>
			</div>
			<div style="padding:5px;">
				<div style="float:left;">确认密码:</div>
				<input id="checkPassword" type="password" name="checkPassword"/>
				<font id="checkPasswd" style="color: red;font-size: 15px;margin-left: 10px;"></font>
			</div>
			<div style="margin-top: 10px;">
				<input id="submit" type="submit" value="修改密码"/>
			</div>
		</div>
	</div>
	<script>
			$(function() {
				
				$("#panel").panel({
					title:'个人信息',
					iconCls:'icon-edit',
					height:'520',
				});
				
				var id=$("#id").val();
				$.ajax({
					type : "POST",
					data : {
						id : id ,
					},
					url : "searcRoles.action",
					dataType : "json",
					success:function(data){
		            	if (data.success==true){
		            		console.log(data);
		            		$("#searcRoles").html("用户类型   : " + data.roles);
		            	}
		            }
				});
				$("#password").blur(function(){
					  var id=$("#id").val();
					  var password=$("#password").val();
					 // alert("pp" + password);
					  if(password==null||password==""){
						  $("#passwd").html("密码不能为空！");
					  }else{
						  $.ajax({
								type : "POST",
								data : {
									id:id ,
									password : password ,
								},
								url : "searchPasswd.action",
								dataType : "json",
								success:function(data){
					            	if (data.success==true){
					            		checkNewPassword();
					            		$("#passwd").html("密码正确");
					            	}else{
					            		$("#passwd").html("密码错误！");
					            	}
					            		
					            }
							});
					
					  }
				});
				
				$("#password").focus(function(){
					$("#passwd").html("");
				});
				$("#checkPassword").focus(function(){
					$("#checkPasswd").html("");
				});
				$("#newPassword").focus(function(){
					$("#checkPasswd").html("");
				});
				function checkNewPassword(){
					$("#checkPassword").blur(function(){
						  var checkNewPassword=$("#checkPassword").val();
						  var newPassword=$("#newPassword").val();
						  //alert("pp" + checkNewPassword + newPassword);
						  if(newPassword==null||newPassword==""){
							  $("#newPasswd").html("请输入新密码!");
						  }else{
							  if(checkNewPassword==newPassword){
								  $("#checkPasswd").html("两次输入的密码一致！");
								  submit(checkNewPassword);
							  }else{
								  $("#checkPasswd").html("两次输入的密码不一致！");
							  }
						  }
						  
			});}
			  function submit(checkNewPassword){
				  var id=$("#id").val();
				  if(checkNewPassword==null||checkNewPassword==""){
					 // alert("p"+checkNewPassword);
					  $("#checkPasswd").html("两次输入的密码不一致！");
				  }else{
					  $("#submit").click(function(){
						  $.ajax({
								type : "POST",
								data : {
									id:id ,
									password : checkNewPassword ,
								},
								url : "updatePasswd.action",
								dataType : "json",
								success:function(data){
									$("#passwd").html("");
									$("#newPassword").html("");
									$("#checkPasswd").html("");
									$("#password").val("");
									$("#newPassword").val("");
									$("#checkPassword").val("");
					            	if (data.success==true){
					            		$.messager.show({
											title : '信息',
											msg : data.message
										});
					            	}
					            		
					            }
							});
					  });

				  }
				 
			  }
		});
			
		//}
	</script>
  </body>
  
</html>
